package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.dao.StaffDao;
import com.example.demo.entity.Staff;
import com.example.demo.service.StaffService;
import com.example.demo.vo.Result;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author: Tian
 * @version: 1.0
 * @since: 1.0
 * @date: 2024/4/17/19:24
 */
@Service
public class StaffServiceImpl implements StaffService {
      @Resource
      StaffDao staffDao;

    /**
     * 查询所有
     * @param current 页码
     * @param pageSize 页面条数
     * @return
     */
      public Result selectAll(Integer current,Integer pageSize,Staff staff){
          IPage<Staff> page = new Page<>(current,pageSize);

          QueryWrapper<Staff> queryWrapper=new QueryWrapper<>();
          if(staff.getId()!=null){
                  queryWrapper.eq("id",staff.getId());
          }
          if(staff.getStaffname()!=null && !staff.getStaffname().equals("")){
                  queryWrapper.like("staffname",staff.getStaffname());
          }
          if(staff.getDeptid()!=null){
                  queryWrapper.eq("deptid",staff.getDeptid());
          }
          IPage<Staff> staffIPage=staffDao.selectPage(page,queryWrapper);

          return new Result(200,"查询成功",staffIPage);
      }

    /**
     * 根据id查询员工信息
     * @param id
     * @return
     */
      public Result selectById(Integer id){
          Staff staff = staffDao.selectById(id);
          return new Result(200,"查询成功",staff);
      }

    /**
     * 根据id修改员工信息
     * @param staff
     * @return
     */
      public Result updateById(Staff staff){
          int i = staffDao.updateById(staff);
          return new Result(200,"修改成功",i);
      }


    /**
     * 根据id删除员工信息
     * @return
     */
    public Result deleteById(Integer id){
        int i = staffDao.deleteById(id);
        return new Result(200,"删除成功",i);
    }

    public Result insertStaff(Staff staff){
        int i = staffDao.insert(staff);
        return new Result(200,"添加成功",i);
    }

   /*   public Result updateByWhere(Staff staff){
          UpdateWrapper<Staff> updateWrapper=new UpdateWrapper<>();
          updateWrapper.like("staffname",staff.getStaffname());
          int update = staffDao.update(staff, updateWrapper);

      }*/

}
